/********************************************************************************************************
 * @file    sampleSensorEpCfg.c
 *
 * @brief   This is the source file for sampleSensorEpCfg
 *
 * @author  Zigbee Group
 * @date    2021
 *
 * @par     Copyright (c) 2021, Telink Semiconductor (Shanghai) Co., Ltd. ("TELINK")
 *			All rights reserved.
 *
 *          Licensed under the Apache License, Version 2.0 (the "License");
 *          you may not use this file except in compliance with the License.
 *          You may obtain a copy of the License at
 *
 *              http://www.apache.org/licenses/LICENSE-2.0
 *
 *          Unless required by applicable law or agreed to in writing, software
 *          distributed under the License is distributed on an "AS IS" BASIS,
 *          WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *          See the License for the specific language governing permissions and
 *          limitations under the License.
 *
 *******************************************************************************************************/

#if (__PROJECT_TL_CONTACT_SENSOR__)

/**********************************************************************
 * INCLUDES
 */
#include "tl_common.h"
#include "zcl_include.h"
#include "sampleSensor.h"

/**********************************************************************
 * LOCAL CONSTANTS
 */
#ifndef ZCL_BASIC_MFG_NAME
#define ZCL_BASIC_MFG_NAME     {4,'L','U','M','I'}
#endif
#ifndef ZCL_BASIC_MODEL_ID
#define ZCL_BASIC_MODEL_ID	   {14,'l','u','m','i','.','s','e','n','s','o','r','_','h','t'}
#endif


/**********************************************************************
 * TYPEDEFS
 */


/**********************************************************************
 * GLOBAL VARIABLES
 */
/**
 *  @brief Definition for Incoming cluster / Sever Cluster
 */
const u16 sampleSensor_inClusterList[] =
{
	ZCL_CLUSTER_GEN_BASIC,
	ZCL_CLUSTER_GEN_IDENTIFY,
	ZCL_CLUSTER_MS_TEMPERATURE_MEASUREMENT,
	ZCL_CLUSTER_MS_RELATIVE_HUMIDITY,
};

/**
 *  @brief Definition for Outgoing cluster / Client Cluster
 */
const u16 sampleSensor_outClusterList[] =
{

};

/**
 *  @brief Definition for Server cluster number and Client cluster number
 */
#define SAMPLESENSOR_IN_CLUSTER_NUM		(sizeof(sampleSensor_inClusterList)/sizeof(sampleSensor_inClusterList[0]))
#define SAMPLESENSOR_OUT_CLUSTER_NUM	(sizeof(sampleSensor_outClusterList)/sizeof(sampleSensor_outClusterList[0]))

/**
 *  @brief Definition for simple description for HA profile
 */
const af_simple_descriptor_t sampleSensor_simpleDesc =
{
	HA_PROFILE_ID,                      	/* Application profile identifier */
	HA_DEV_SIMPLE_SENSOR,                	    /* Application device identifier */
	SAMPLE_SENSOR_ENDPOINT,         		/* Endpoint */
	0,                                  	/* Application device version */
	0,										/* Reserved */
	SAMPLESENSOR_IN_CLUSTER_NUM,           	/* Application input cluster count */
	SAMPLESENSOR_OUT_CLUSTER_NUM,          	/* Application output cluster count */
	(u16 *)sampleSensor_inClusterList,    	/* Application input cluster list */
	(u16 *)sampleSensor_outClusterList,   	/* Application output cluster list */
};

/* Basic */
zcl_basicAttr_t g_zcl_basicAttrs =
{
	.zclVersion 	= 0x01,
	.appVersion 	= 0x02,
	.stackVersion 	= 0x02,
	.hwVersion		= 0x1E,
	.manuName		= ZCL_BASIC_MFG_NAME,
	.modelId		= ZCL_BASIC_MODEL_ID,
	.powerSource	= POWER_SOURCE_BATTERY,
	.deviceEnable	= TRUE,
};
const zclAttrInfo_t basic_attrTbl[] =
{
	{ ZCL_ATTRID_BASIC_ZCL_VER,      		ZCL_DATA_TYPE_UINT8,    ACCESS_CONTROL_READ,  						(u8*)&g_zcl_basicAttrs.zclVersion},
	{ ZCL_ATTRID_BASIC_APP_VER,      		ZCL_DATA_TYPE_UINT8,    ACCESS_CONTROL_READ,  						(u8*)&g_zcl_basicAttrs.appVersion},
	{ ZCL_ATTRID_BASIC_STACK_VER,    		ZCL_DATA_TYPE_UINT8,    ACCESS_CONTROL_READ,  						(u8*)&g_zcl_basicAttrs.stackVersion},
	{ ZCL_ATTRID_BASIC_HW_VER,       		ZCL_DATA_TYPE_UINT8,    ACCESS_CONTROL_READ,  						(u8*)&g_zcl_basicAttrs.hwVersion},
	{ ZCL_ATTRID_BASIC_MFR_NAME,     		ZCL_DATA_TYPE_CHAR_STR, ACCESS_CONTROL_READ,  						(u8*)g_zcl_basicAttrs.manuName},
	{ ZCL_ATTRID_BASIC_MODEL_ID,     		ZCL_DATA_TYPE_CHAR_STR, ACCESS_CONTROL_READ,  						(u8*)g_zcl_basicAttrs.modelId},
	{ ZCL_ATTRID_BASIC_POWER_SOURCE, 		ZCL_DATA_TYPE_ENUM8,    ACCESS_CONTROL_READ,  						(u8*)&g_zcl_basicAttrs.powerSource},
	{ ZCL_ATTRID_BASIC_DEV_ENABLED,  		ZCL_DATA_TYPE_BOOLEAN,  ACCESS_CONTROL_READ | ACCESS_CONTROL_WRITE, (u8*)&g_zcl_basicAttrs.deviceEnable},

	{ ZCL_ATTRID_GLOBAL_CLUSTER_REVISION, 	ZCL_DATA_TYPE_UINT16,  	ACCESS_CONTROL_READ,  						(u8*)&zcl_attr_global_clusterRevision},
};
#define ZCL_BASIC_ATTR_NUM 				sizeof(basic_attrTbl) / sizeof(zclAttrInfo_t)
/* Basic END*/


/* Identify */
zcl_identifyAttr_t g_zcl_identifyAttrs =
{
	.identifyTime	= 0x0000,
};
const zclAttrInfo_t identify_attrTbl[] =
{
	{ ZCL_ATTRID_IDENTIFY_TIME,  			ZCL_DATA_TYPE_UINT16,   ACCESS_CONTROL_READ | ACCESS_CONTROL_WRITE, (u8*)&g_zcl_identifyAttrs.identifyTime },

	{ ZCL_ATTRID_GLOBAL_CLUSTER_REVISION, 	ZCL_DATA_TYPE_UINT16,  	ACCESS_CONTROL_READ,  						(u8*)&zcl_attr_global_clusterRevision},
};
#define ZCL_IDENTIFY_ATTR_NUM			sizeof(identify_attrTbl) / sizeof(zclAttrInfo_t)
/* Identify END*/

/*Temperature*/
zcl_temperatureAttr_t g_zcl_temperatureAttrs =
{
		.temperatureValue = 0x0000,
};
const zclAttrInfo_t temperature_measurement_attrTbl[] =
{
	{ ZCL_TEMPERATURE_MEASUREMENT_ATTRID_MEASUREDVALUE, ZCL_DATA_TYPE_INT16,    ACCESS_CONTROL_READ | ACCESS_CONTROL_REPORTABLE, 	(u8*)&g_zcl_temperatureAttrs.temperatureValue},

	{ ZCL_ATTRID_GLOBAL_CLUSTER_REVISION, 				ZCL_DATA_TYPE_UINT16,   ACCESS_CONTROL_READ,  							(u8*)&zcl_attr_global_clusterRevision},
};
#define ZCL_TEMPERATURE_ATTR_NUM			sizeof(temperature_measurement_attrTbl) / sizeof(zclAttrInfo_t)
/*Temperature END*/

/*Humidity*/
zcl_humidityAttr_t g_zcl_humidityAttrs =
{
		.humidityValue = 0x0000,
};
const zclAttrInfo_t humidity_measurement_attrTbl[] =
{
	{ ZCL_HUMIDITY_MEASUREMENT_ATTRID_MEASUREDVALUE, 	ZCL_DATA_TYPE_UINT16,    ACCESS_CONTROL_READ | ACCESS_CONTROL_REPORTABLE, 	(u8*)&g_zcl_humidityAttrs.humidityValue},

	{ ZCL_ATTRID_GLOBAL_CLUSTER_REVISION, 				ZCL_DATA_TYPE_UINT16,   ACCESS_CONTROL_READ,  							(u8*)&zcl_attr_global_clusterRevision},
};
#define ZCL_HUMIDITY_ATTR_NUM			sizeof(humidity_measurement_attrTbl) / sizeof(zclAttrInfo_t)
/*Humidity END*/

/*POWER CFG*/
zcl_powerCFGAttr_t g_zcl_powerCFGAttrs =
{
		.batteryVoltage 			= 0x00,
		.batteryPercentRemaining 	= 0x00,
};

const zclAttrInfo_t power_config_attrTbl[] =
{
		{ZCL_ATTRID_BATTERY_VOLTAGE,						ZCL_DATA_TYPE_UINT8, 	ACCESS_CONTROL_READ,							(u8*)&g_zcl_powerCFGAttrs.batteryVoltage                  },
		{ZCL_ATTRID_BATTERY_PERCENTAGE_REMAINING,			ZCL_DATA_TYPE_UINT8, 	ACCESS_CONTROL_READ|ACCESS_CONTROL_REPORTABLE,	(u8*)&g_zcl_powerCFGAttrs.batteryPercentRemaining      },

		{ZCL_ATTRID_GLOBAL_CLUSTER_REVISION, 							ZCL_DATA_TYPE_UINT16,  	ACCESS_CONTROL_READ,  							(u8*)&zcl_attr_global_clusterRevision},
};

#define ZCL_POWERCFG_ATTR_NUM			sizeof(power_config_attrTbl) / sizeof(zclAttrInfo_t)


/**
 *  @brief Definition for simple contact sensor ZCL specific cluster
 */
const zcl_specClusterInfo_t g_sampleSensorClusterList[] =
{
	{ZCL_CLUSTER_GEN_BASIC,						MANUFACTURER_CODE_NONE, 	ZCL_BASIC_ATTR_NUM, 		basic_attrTbl,  				zcl_basic_register,						sampleSensor_basicCb},
	{ZCL_CLUSTER_GEN_IDENTIFY,					MANUFACTURER_CODE_NONE, 	ZCL_IDENTIFY_ATTR_NUM,		identify_attrTbl,				zcl_identify_register,					sampleSensor_identifyCb},
	{ZCL_CLUSTER_MS_TEMPERATURE_MEASUREMENT,	MANUFACTURER_CODE_NONE, 	ZCL_TEMPERATURE_ATTR_NUM,	temperature_measurement_attrTbl,zcl_temperature_measurement_register,	sampleSensor_temperatureCb},
	{ZCL_CLUSTER_MS_RELATIVE_HUMIDITY,			MANUFACTURER_CODE_NONE, 	ZCL_HUMIDITY_ATTR_NUM,		humidity_measurement_attrTbl,	zcl_humidity_measurement_register,		sampleSensor_humidityCb},
	{ZCL_CLUSTER_GEN_POWER_CFG,					MANUFACTURER_CODE_NONE, 	ZCL_POWERCFG_ATTR_NUM,		power_config_attrTbl,			zcl_powerCfg_register,					sampleSensor_powerCFGCb},
};

u8 SAMPLE_SENSOR_CB_CLUSTER_NUM = (sizeof(g_sampleSensorClusterList)/sizeof(g_sampleSensorClusterList[0]));

/**********************************************************************
 * FUNCTIONS
 */




#endif	/* __PROJECT_TL_CONTACT_SENSOR__ */
